package collections;

import com.google.common.collect.ImmutableList;
import com.google.common.collect.ImmutableSet;
/**
 * 当Collection内容不应该被改变时，使用对应的不可变类，他比可变类更加安全，更小内存占用，线程同步时也不用担心数据被破坏
 * @author tiangh
 * 2013-5-26 下午4:55:25
 */
public class ImmutableDemo {

	/**
	 * @param args
	 */
	public static void main(String[] args) {
		immutableConstructor();
	}
	
	
	public static void immutableConstructor() {
		
		ImmutableSet<String> colorSet=ImmutableSet.of("red","orange","yellow","green","blue","purple");
		
		@SuppressWarnings("unused")
		ImmutableList<String> colorList = ImmutableList.copyOf(colorSet);
		
		@SuppressWarnings("unused")
		ImmutableSet<Object> appendedColorSet = ImmutableSet.builder().addAll(colorSet).add("black").build();
	}

}
